package bdeenyy.threevector.util;

import bdeenyy.threevector.model.VectorData;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.input.Clipboard;

public class ClipboardHandler {
    public ObservableList<VectorData> pasteFromClipboard() {
        ObservableList<VectorData> dataFromClipboard = FXCollections.observableArrayList();
        Clipboard clipboard = Clipboard.getSystemClipboard();
        String content = clipboard.getString();
        if (content != null) {
            for (String line : content.split("\n")) {
                String[] fields = line.split("\t");
                if (fields.length == 4) {
                    dataFromClipboard.add(new VectorData(fields[0], fields[1], fields[2], fields[3]));
                }
            }
        }
        return dataFromClipboard;
    }
}
